﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace PMS.DAL
{
    public class DepotDAL
    {
        private readonly string sql = "select Id,DepotName from P_Depot";        
        public bool IsExist(string name)
        {
            string strsql = "select Id from P_Depot where DepotName='"+name+"'";
            if (DBUtility.SQLHelper.Execute(strsql) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Insert(Model.Depot dep)
        {
            
                string strsql = "insert into P_Depot (DepotName) values('"+dep.DepotName+"')";
                return Convert.ToBoolean(DBUtility.SQLHelper.Execute(strsql));
        }
        public bool Update(Model.Depot dep)
        {
            return true;
        }
        public bool Delete(string id)
        {
            return true;
        }
        public IList<Model.Depot> GetList()
        {            
            List<Model.Depot> depList = new List<PMS.Model.Depot>();
            System.Data.DataSet ds = PMS.DBUtility.SQLHelper.GetData(sql); 
            
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                Model.Depot dep = new PMS.Model.Depot();
                dep.Id = (int)row[0];
                dep.DepotName = (string)row[1];
                depList.Add(dep);
            }
            return depList;
        }
    }
}
